package com.app.app_service.controller;

import com.app.app_service.bean.ActionBean;
import com.app.app_service.bean.ResultBean;
import com.app.app_service.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by jiacheng on 2017/9/13.
 *
 */
@RestController
@RequestMapping("/app/user")
@Api(value = "UserController",description= "luckyBear用户模块相关接口")
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/getUserData", method = RequestMethod.POST)
    @ApiOperation(value="获取用户信息", notes="获取用户信息")
//    @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long",paramType = "path")
    public ActionBean getUserData(@ApiParam(name="id",value="用户id",required=true) @RequestParam(value="id") Long id){
        ResultBean regist = userService.getUserData(id);
        ActionBean message = new ActionBean();
        if(regist.isResult()){
            message.setResult(true);
            message.setCode(200);
            message.setResponse(regist.getData());
        }else{
            message.setResult(false);
            message.setCode((Integer)(regist.getData()));
            message.setErrorMessage(regist.getMessage());
        }
        return message;
    }

    /**
     * 模糊查询用户
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/listUsers", method = RequestMethod.POST)
    @ApiOperation(value="模糊查询获取用户列表", notes="模糊查询获取用户列表")
    public ActionBean listUsers(@ApiParam(name="name",value="用户名称",required=true) @RequestParam(value="name") String name){

        ResultBean regist = userService.listUsers(name);
        ActionBean message = new ActionBean();
        if(regist.isResult()){
            message.setResult(true);
            message.setCode(200);
            message.setResponse(regist.getData());
        }else{
            message.setResult(false);
            message.setCode((Integer)(regist.getData()));
            message.setErrorMessage(regist.getMessage());
        }
        return message;
    }
}
